<template>
    <el-button @click="login" type="primary" class="button1">Login</el-button>
</template>
  
<script lang="ts" setup>
import { post } from '../utils/request'
import { useRouter } from 'vue-router';
const confirmApi = process.env.VUE_APP_CONFIRM_API
const router = useRouter()

const form = defineProps({
    contact: {
        type: String
    }, 
    verifyCode: {
        type: String
    }, 
    verifyId: {
        type: String
    }, 
    verifyType: {
        type: String
    }
})

const login = () => {
  post(confirmApi, {
    userName: form.contact,
    verifyType: form.verifyType?.toLowerCase(),
    verifyId: form.verifyId,
    verificationCode: form.verifyCode
  }).then(
    respnose => {
      console.log(respnose)
      if (respnose.data.msg == "验证码正确"){
        var d = new Date()
        localStorage.setItem(
          "auth_token", JSON.stringify({token:respnose.data.auth_token, timestamp: d.getTime()}))
        router.push({
            path: "/loginsuccess"
        })
        return
      }
      alert("验证码错误")
    }
  )}
</script>

<style scoped>
.button1 {
  display: inline-block;
  width: 60%;
  background-color: var(--color-green);
}
</style>